package com.touchfish.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.touchfish.material.domain.TGoodsMaterial;
import com.touchfish.material.mapper.MaterialMapper;
import com.touchfish.material.service.MaterialService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, TGoodsMaterial> implements MaterialService {
    //查詢全部
    @Override
    public List<TGoodsMaterial> getMaterialList() {
        /**
         *  @Param current:页码
         *  @Param size:每页记录数
         */
        IPage<TGoodsMaterial> materialPage=new Page<>(2,4);
        QueryWrapper<TGoodsMaterial> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("material_name");
        return super.page(materialPage, queryWrapper).getRecords();
    }
    //条件查询（name,code）
    @Override
    public List<TGoodsMaterial> listMaterial(String condition) {
        IPage<TGoodsMaterial> materialPage=new Page<>(2,4);
        QueryWrapper<TGoodsMaterial> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("material_name", condition).or().like("material_name", condition);
        return super.page(materialPage, queryWrapper).getRecords();
    }

    //条件删除（name,code）
    @Override
    public void delMaterial(String condition) {
        LambdaQueryWrapper<TGoodsMaterial> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.like(TGoodsMaterial::getMaterialName, condition).or().like(TGoodsMaterial::getMaterialCode, condition);
        super.remove(lambdaQuery);
    }

    @Override
    public void updateMaterial(TGoodsMaterial material) {
        super.updateById(material);
    }

    @Override
    public void createMaterial(TGoodsMaterial material) {
        super.save(material);
    }


}
